package sim1011.examples.test1;

import jade.wrapper.AgentContainer;
import jade.core.ContainerID;
import jade.core.Profile;
import jade.core.ProfileImpl;
import jade.core.ResourceManager;
import jade.core.Runtime;
import jade.wrapper.AgentController;
import jade.wrapper.ContainerController;
import jade.wrapper.ControllerException;
import jade.wrapper.StaleProxyException;

public class SmallBrain {
	private AgentController[] agentC0 = new AgentController[10];
	private AgentController[] agentC1 = new AgentController[10];
	
	public static void main(String[] argv) {
		SmallBrain brain = new SmallBrain();
		brain.start();
	}
	
	public void start() {
		// create a container
		Runtime t = Runtime.instance();
		Profile p0 = new ProfileImpl();
		p0.setParameter(Profile.LOCAL_HOST, "localhost");
		p0.setParameter(Profile.PLATFORM_ID, "sim-platform");
		p0.setParameter(Profile.CONTAINER_NAME, "fixedNode.0");
		AgentContainer pl0 = (AgentContainer) t.createMainContainer(p0);
		Profile p1 = new ProfileImpl();
		p1.setParameter(Profile.LOCAL_HOST, "localhost");
		p1.setParameter(Profile.PLATFORM_ID, "sim-platform");
		p1.setParameter(Profile.CONTAINER_NAME, "fixedNode.1");
		AgentContainer pl1 = t.createAgentContainer(p1);
		// create a DummyAgent
		try {
			System.out.println("Created: " + pl0.getContainerName());
			System.out.println("Created: " + pl0.getPlatformName());
			System.out.println("Created: " + pl1.getContainerName());
			System.out.println("Created: " + pl1.getPlatformName());
			for (int i=0; i<agentC0.length; ++i) {
				agentC0[i] = pl0.createNewAgent("agent0." + i, "sim1011.examples.test1.Component", new Object[1]);
				agentC1[i] = pl0.createNewAgent("agent1." + i, "sim1011.examples.test1.Component", new Object[1]);
				agentC0[i].start();
				agentC1[i].start();
			}
			ContainerID pl1Container = new ContainerID();
			pl1Container.setName("fixedNode.1");
			pl1Container.setAddress("localhost");
		} catch (StaleProxyException e) {
			e.printStackTrace();
		} catch (ControllerException e) {
			e.printStackTrace();
		}
	}
}
